package lhdx10;

public class CarRental {
    private String companyName;
    private String phone;
    private double shouR;
    private JiLu[] record=new JiLu[1000];
    Automobile[] a = new Automobile[200];
    private int k = 0;
    private int h=0;

    public double getShouR() {
        return shouR;
    }

    public void setShouR(double shouR) {
        this.shouR = shouR;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public CarRental(String companyName, String phone) {
        this.companyName = companyName;
        this.phone = phone;
    }

    public void xinX() {
        System.out.println(companyName + "欢迎你！" + ",请致电" + phone + "洽谈相关业务。");
        System.out.println("现在有" + k + "辆车出租！");
    }

    public boolean purchase(Automobile A) {
        if (k >= a.length) {
            Automobile[] a2 = new Automobile[a.length+100];
            for (int i=0;i<k;i++){
                a2[i]=a[i];
            }
            a=a2;
            System.out.println("已扩容！");
            return true;
        }
            a[k++]=A;
        return true;
    }

    public void message() {
        System.out.println("车辆租赁信息如下：");
        for (int i = 0; i < k; i++) {
            a[i].show();
        }
    }
    public int zuLin1(String type) {
        int j=0;
        for (int i = 0; i < k; i++) {
            if (a[i].getType().equals(type)&&a[i].isState()==true) {
                a[i].show();
                j++;
            }
        }
        return j;
    }

    public Automobile zuLin(String plateNumber) {
        for (int i = 0; i < k; i++) {
            if (a[i].getPlateNumber().equals(plateNumber)) {
                if (a[i].isState()==true) {
                    System.out.print("你要租的是：");
                    a[i].show();
                    return a[i];
                }
                System.out.println("此车已出租，无法再租。");
                return null;
            }
        }
        System.out.println("租赁失败,查无此车。");
        return null;
    }


    public void zuLin2(String type,String plateNumber,int a1) {
        for (int i = 0; i < k; i++) {
            if (type.equals("客车") &&a[i].getPlateNumber().equals(plateNumber) &&a[i].isState()==true) {
                a[i].payment(a1);
                shouR=shouR+a[i].payment(a1);
                System.out.println("请支付：" + a[i].payment(a1) + "元");
                System.out.println("用车愉快！");
                a[i].setState(false);
                return;
            }
            if (type.equals("轿车") &&a[i].getPlateNumber().equals(plateNumber)&&a[i].isState()==true) {
                a[i].payment(a1);
                shouR=shouR+a[i].payment(a1);
                System.out.println("请支付:" + a[i].payment(a1) + "元");
                System.out.println("用车愉快！");
                a[i].setState(false);
                return;
            }
        }
    }
    public void haiChe(String plateNumber) {
        for (int i = 0; i < k; i++) {
            if (a[i].getPlateNumber().equals(plateNumber)&&a[i].isState()==false) {
                System.out.println("还车成功！下次继续合作！");
                a[i].setState(true);
                return;
            }
        }
        System.out.println("还车失败，请核对信息。");
        return;
    }

    public void baoFei(String plateNumber) {
        for (int i = 0; i < k; i++) {
            if (a[i].getPlateNumber().equals(plateNumber)&&a[i].isState()==true) {
                for (int j = i; j < k - 1; j++) {
                    a[j] = a[j + 1];
                }
                a[k - 1] = null;
                k--;
                System.out.println("已报废！");
                return;
            }
        }
        System.out.println("报废失败，请核对信息。");
    }
    public double shouRu(){
        System.out.println("公司租车的总收入是："+shouR+"元");
        return shouR;
    }
    public void add( String name,String phone,String plateNumber,int days){
        if (h>=record.length){
            JiLu[] a2 = new JiLu[record.length+100];
            for (int i=0;i<h;i++){
                a2[i]=record[i];
            }
            record=a2;
        }
        record[h++]=new JiLu(name,phone,plateNumber,days);

    }
    public void chaJiLi(){
        for (int i=0;i<h;i++){
            System.out.println(record[i]);
        }
    }

}
